﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PMCgui
{
    public partial class LanguageUserControl : UserControl
    {
        public LanguageUserControl()
        {
            InitializeComponent();
            Dock = DockStyle.Fill;
            cbLanguages.DataSource = Language.Instance.GetAvailableLanguages();
            cbLanguages.DisplayMember = "NativeName";
            cbLanguages.SelectedItem = Language.CultureInfo;

            cbLanguages.SelectedIndexChanged += new EventHandler(cbLanguages_SelectedIndexChanged);
        }

        void cbLanguages_SelectedIndexChanged(object sender, EventArgs e)
        {
            Language.CultureInfo = (CultureInfo)cbLanguages.SelectedItem;
            Language.Reset();
        }

        void btnModifyLanguage_Click(object sender, System.EventArgs e)
        {
            String file = GetPathFromDialog();
            if (file != null)
                Language.Instance.GenerateLanguageXML(file);
        }

        void btnCreateNewLanguage_Click(object sender, System.EventArgs e)
        {
            String file = GetPathFromDialog();
            if (file != null)
                Language.GenerateNewLanguageXML(file);
        }

        private String GetPathFromDialog()
        {
            SaveFileDialog dialog = new SaveFileDialog
            {
                Filter = "Language files | *.lang",
            };
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                return dialog.FileName;
            }
            return null;
        }
    }
}
